﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;

public partial class reco_step : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DBaccess db = new DBaccess();
        DataSet ds = new DataSet();
        if (!IsPostBack)
        {
            ds = db.GetDataSet("select * from mr_v_recommand");
            GridView1.DataSource = ds;
            GridView1.DataBind();
            PanelNei.Visible = false;
            PanelRank.Visible = false;
            PanelScore.Visible = false;
        }
        Session["mid"] = 2;
        int sid = int.Parse(Session["mid"].ToString());
        DataSet ds1 = new DataSet();
        DataSet ds2 = new DataSet();
        DataSet ds3 = new DataSet();
        DataSet ds4 = new DataSet();
        DataSet ds5 = new DataSet();
        String sql1 = "select download_weight from mr_member where mid = '" + sid + "'";
        String sql2 = "select preference_weight from mr_member where mid = '" + sid + "'";
        String sql3 = "select time_weight from mr_member where mid = '" + sid + "'";
        String sql4 = "select difficulty_weight from mr_member where mid = '" + sid + "'";
        ds1 = db.GetDataSet(sql1);
        TextBoxDownload.Text = ds1.Tables[0].Rows[0][0].ToString();
        ds2 = db.GetDataSet(sql2);
        TextBoxPreference.Text = ds2.Tables[0].Rows[0][0].ToString();
        ds3 = db.GetDataSet(sql3);
        TextBoxTime.Text = ds3.Tables[0].Rows[0][0].ToString();
        ds4 = db.GetDataSet(sql4);
        TextBoxGPA.Text = ds4.Tables[0].Rows[0][0].ToString();
        sql1 = "select value from mr_parameter where pname = 'sim'";
        sql2 = "select value from mr_parameter where pname = 'GPAperscore'";
        ds1 = db.GetDataSet(sql1);
        TextBoxSim.Text = ds1.Tables[0].Rows[0][0].ToString();
        ds2 = db.GetDataSet(sql2);
        TextGPAperscore.Text = ds2.Tables[0].Rows[0][0].ToString();

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        String sid = Session["mid"].ToString();
        if (double.Parse(TextBoxSim.Text) < 1)
        {
            DBaccess db = new DBaccess();
            String[] sql = new String[2];
            sql[0] = "update mr_parameter set sim = '" + TextBoxSim.Text + "'";
            sql[1] = "update mr_parameter set GPAperscore = '" + TextGPAperscore.Text + "'";
            db.ExecTranscation(sql);
            Response.Write("<script>alert('修改成功!');</script>");
        }
        else
            Response.Write("<script>alert('用户筛选相似度小于1');</script>");
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        String sid = Session["mid"].ToString();
        if (double.Parse(TextBoxDownload.Text) + double.Parse(TextBoxPreference.Text) + double.Parse(TextBoxTime.Text) + double.Parse(TextBoxGPA.Text) == 1)
        {
            DBaccess db = new DBaccess();
            String[] sql = new String[5];
            sql[0] = "update mr_parameter set value = '" + TextBoxDownload.Text + "' where pname = 'download'";
            sql[1] = "update mr_parameter set value = '" + TextBoxPreference.Text + "' where pname = 'preference'";
            sql[0] = "update mr_parameter set value = '" + TextBoxTime.Text + "' where pname = 'time'";
            sql[0] = "update mr_parameter set value = '" + TextBoxGPA.Text + "' where pname = 'difficulty'";
            sql[4] = "EXEC sp_memberinit";
            db.ExecTranscation(sql);

            Response.Write("<script>alert('推送成功!');</script>");
        }
        else
            Response.Write("<script>alert('请确保各权值总和为100%');</script>");
    }
    protected void ButtonStep1_Click(object sender, EventArgs e)
    {
        PanelMatrix.Visible = true;
        PanelNei.Visible = false;
        PanelRank.Visible = false;
        PanelScore.Visible = false;
    }
    protected void ButtonStep2_Click(object sender, EventArgs e)
    {
    }
}